<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'collection-form',
	'enableAjaxValidation'=>false,
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>
<table>
<tr>
<td colspan="2">
		<?php echo $form->LabelEx($model['collection'],'req_date'); ?>
		<?php $this->widget('zii.widgets.jui.CJuiDatePicker',
              array(
                    'model'=>$model['collection'],
                    'attribute'=>"req_date",
                    'htmlOptions'=>array('value'=>(!empty($model['collection']->in_date))?(is_numeric($model['collection']->in_date))?date('d/m/Y',$model['collection']->in_date):$model['collection']->in_date:date('d/m/Y')),
                    'options'=>array('dateFormat'=>'dd/mm/yy'),
                   )
             );
?>
</td>
</tr>
<tr>
	<td>

		<?php echo $form->LabelEx($model['collection'],'company'); ?>
		<?php echo $form->TextField($model['collection'],'company',array('readonly'=>'readonly','size'=>50)); ?>
<br />
		<?php echo $form->LabelEx($model['collection'],'address'); ?>
		<?php echo CHtml::dropDownList('collection_add',0,$cargo->shipper()->getAddress()); ?>
		<?php echo CHtml::link('Select','#',array('id'=>'addAddress')); ?><br />
		<?php echo $form->TextArea($model['collection'],'address',array('rows'=>3,'cols'=>40)); ?>
		<?php echo $form->error($model['collection'],'address'); ?>
<br />
		<?php echo $form->LabelEx($model['collection'],'attn'); ?>
		<?php echo CHtml::dropDownList('collection_contact',0,$cargo->shipper()->getContact()); ?>
		<?php echo CHtml::link('Add','#',array('id'=>'addContact')); ?><br />
		<?php echo $form->TextField($model['collection'],'attn',array('size'=>50, 'maxlength'=>125)); ?>

	</td>
	<td>
		<?php echo $form->LabelEx($model['collection'],'consignee'); ?>
		<?php echo $form->TextField($model['collection'],'consignee',array('readonly'=>'readonly','size'=>50)); ?>
	<br />
		<?php echo $form->LabelEx($model['collection'],'delivery_add'); ?>
		<?php echo CHtml::dropDownList('delivery_add',0,$cargo->consignee()->getAddress()); ?>
		<?php echo CHtml::link('Select','#',array('id'=>'addDelAddress')); ?><br />
		<?php echo $form->TextArea($model['collection'],'delivery_add',array('rows'=>3,'cols'=>40)); ?>
		<?php echo $form->error($model['collection'],'delivery_add'); ?>
	<br />
		<?php echo $form->LabelEx($model['collection'],'delivery_attn'); ?>
		<?php echo CHtml::dropDownList('delivery_contact',0,$cargo->consignee()->getContact()); ?>
		<?php echo CHtml::link('Add','#',array('id'=>'addDelContact')); ?><br />
		<?php echo $form->TextField($model['collection'],'delivery_attn',array('size'=>50, 'maxlength'=>125)); ?>

	</td>
</tr>

<tr>
<td colspan="2">
		<?php echo $form->LabelEx($model['collection'],"pkg_id")?>
		<?php echo $form->TextField($model['detail'],"wt",array('size'=>5,'maxlength'=>11,'placeholder'=>'Weight')); ?>
        <?php echo $form->DropDownList($model['detail'], "wt_type", $model['detail']->wttype,array('style'=>'width:60px;'));?>
        <?php echo $form->TextField($model['detail'],"qty",array('size'=>5,'maxlength'=>11,'placeholder'=>'Quatity')); ?>
        <?php echo $form->DropDownList($model['detail'], "qty_type", $model['detail']->qtytype,array('style'=>'width:60px;'));?>
        <?php echo $form->TextField($model['detail'],"m3",array('size'=>5,'maxlength'=>11,'placeholder'=>'M3')); ?>
        <?php echo $form->DropDownList($model['detail'], "m3_type", $model['detail']->m3type,array('style'=>'width:60px;'));?>

</td>
</tr>
<tr>
<td colspan="2">
		<?php echo $form->LabelEx($model['collection'],'tools'); ?>
		<?php echo $form->TextField($model['collection'],'tools',array('maxlength'=>250)); ?>
		<?php echo $form->error($model['collection'],'tools'); ?>
	<br />
		<?php echo $form->LabelEx($model['collection'],'remark'); ?>
		<?php echo $form->TextArea($model['collection'],'remark',array('rows'=>4, 'cols'=>50)); ?>
		<?php echo $form->error($model['collection'],'remark'); ?>

</td>
</tr>
<tr>
	<td colspan="2">
	<div class="row buttons">
		<?php 
        	$this->widget('zii.widgets.jui.CJuiButton',array(
        		'name'=>'submit',
        		'caption'=>'Create',
        		'value'=>"create",
        	)); 
        ?>
	</div>
	</td>
</tr>
</table>
	
	
	<hr />
	
	
	<hr />
	<div class="row">
		
	</div>
	

	

<?php $this->endWidget(); ?>

</div><!-- form -->
<?php
$cs = Yii::app()->ClientScript;
$getCompanyInfoURL = CHtml::normalizeUrl(array('company/getInfo'));
$cargoViewURL = CHtml::normalizeUrl(array('cargo/view','id'=>$cargo->id));
$getAddressUrl = CHtml::normalizeUrl(array('company/getaddress'));
$getContactUrl = CHtml::normalizeUrl(array('company/getcontact'));
$script =<<<EOD
$.collection_create_form = {
	afterSubmit:function(data){
		window.location = "$cargoViewURL";
	}
};
$('#collection-form [type=submit]').click(function(){
	var form = $.extend($.simplelogform,$.collection_create_form);
	form.Submit($('#collection-form'));
	return false;
});
$('#addAddress, #addDelAddress').click(function(){
	var selected = $(this).parent('.row').children('select');
	$(selected).getInfo({url:'$getAddressUrl',success:function(data){
		$(selected).parent('.row').children('textarea').val(data);
	}});
	return false;
});
$('#addContact, #addDelContact').click(function(){
	var selected = $(this).parent('.row').children('select');
	$(selected).getInfo({url:'$getContactUrl',success:function(data){
		var contact = $(selected).parent('.row').children('input').val()+data+',';
		$(selected).parent('.row').children('input').val(contact);
	}});
	return false;
});
EOD;
$cs->registerScript('collection#create#form',$script);
?>